<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: XmlSimple</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">XmlSimple</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../files/vendor/rails/activesupport/lib/active_support/core_ext/hash/conversions_rb.html">
                vendor/rails/activesupport/lib/active_support/core_ext/hash/conversions.rb
                </a>
        <br />
                <a href="../files/vendor/rails/activesupport/lib/active_support/vendor/xml-simple-1_0_11/xmlsimple_rb.html">
                vendor/rails/activesupport/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="Object.html">
                Object
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Easy API to maintain XML (especially configuration files).
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000010">new</a>&nbsp;&nbsp;
      <a href="#M000012">xml_in</a>&nbsp;&nbsp;
      <a href="#M000011">xml_in</a>&nbsp;&nbsp;
      <a href="#M000008">xml_in_string</a>&nbsp;&nbsp;
      <a href="#M000009">xml_in_string</a>&nbsp;&nbsp;
      <a href="#M000013">xml_out</a>&nbsp;&nbsp;
      <a href="#M000014">xml_out</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->
    <div id="includes">
      <h3 class="section-bar">Included Modules</h3>

      <div id="includes-list">
        <span class="include-name"><a href="REXML.html">REXML</a></span>
      </div>
    </div>

    <div id="section">

    <div id="class-list">
      <h3 class="section-bar">Classes and Modules</h3>

      Class <a href="XmlSimple/Cache.html" class="link">XmlSimple::Cache</a><br />

    </div>

    <div id="constants-list">
      <h3 class="section-bar">Constants</h3>

      <div class="name-list">
        <table summary="Constants">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">KNOWN_OPTIONS</td>
          <td>=</td>
          <td class="context-item-value">{     'in'  =&gt; %w(       keyattr keeproot forcecontent contentkey noattr       searchpath forcearray suppressempty anonymoustag       cache grouptags normalisespace normalizespace       variables varattr keytosymbol     ),     'out' =&gt; %w(       keyattr keeproot contentkey noattr rootname       xmldeclaration outputfile noescape suppressempty       anonymoustag indent grouptags noindent     )</td>
          <td width="3em">&nbsp;</td>
          <td class="context-item-desc">
Declare options that are valid for <a
href="XmlSimple.html#M000011">xml_in</a> and <a
href="XmlSimple.html#M000013">xml_out</a>.

</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">DEF_KEY_ATTRIBUTES</td>
          <td>=</td>
          <td class="context-item-value">[]</td>
          <td width="3em">&nbsp;</td>
          <td class="context-item-desc">
Define some reasonable defaults.

</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">DEF_ROOT_NAME</td>
          <td>=</td>
          <td class="context-item-value">'opt'</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">DEF_CONTENT_KEY</td>
          <td>=</td>
          <td class="context-item-value">'content'</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">DEF_XML_DECLARATION</td>
          <td>=</td>
          <td class="context-item-value">&quot;&lt;?xml version='1.0' standalone='yes'?&gt;&quot;</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">DEF_ANONYMOUS_TAG</td>
          <td>=</td>
          <td class="context-item-value">'anon'</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">DEF_FORCE_ARRAY</td>
          <td>=</td>
          <td class="context-item-value">true</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">DEF_INDENTATION</td>
          <td>=</td>
          <td class="context-item-value">'  '</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">DEF_KEY_TO_SYMBOL</td>
          <td>=</td>
          <td class="context-item-value">false</td>
        </tr>
        </table>
      </div>
    </div>



      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000010" class="method-detail">
        <a name="M000010"></a>

        <div class="method-heading">
          <a href="#M000010" class="method-signature">
          <span class="method-name">new</span><span class="method-args">(defaults = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Creates and initializes a <a href="XmlSimple.html#M000010">new</a> <a
href="XmlSimple.html">XmlSimple</a> object.
</p>
<table>
<tr><td valign="top">defaults:</td><td>Default values for options.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000010-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb, line 128</span>
128:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">defaults</span> = <span class="ruby-keyword kw">nil</span>)
129:     <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">defaults</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">defaults</span>.<span class="ruby-identifier">instance_of?</span>(<span class="ruby-constant">Hash</span>)
130:       <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;Options have to be a Hash.&quot;</span>
131:     <span class="ruby-keyword kw">end</span>
132:     <span class="ruby-ivar">@default_options</span> = <span class="ruby-identifier">normalize_option_names</span>(<span class="ruby-identifier">defaults</span>, (<span class="ruby-constant">KNOWN_OPTIONS</span>[<span class="ruby-value str">'in'</span>] <span class="ruby-operator">+</span> <span class="ruby-constant">KNOWN_OPTIONS</span>[<span class="ruby-value str">'out'</span>]).<span class="ruby-identifier">uniq</span>)
133:     <span class="ruby-ivar">@options</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>
134:     <span class="ruby-ivar">@_var_values</span> = <span class="ruby-keyword kw">nil</span>
135:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000012" class="method-detail">
        <a name="M000012"></a>

        <div class="method-heading">
          <a href="#M000012" class="method-signature">
          <span class="method-name">xml_in</span><span class="method-args">(string = nil, options = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
This is the functional version of the instance method <a
href="XmlSimple.html#M000011">xml_in</a>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000012-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000012-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb, line 201</span>
201:   <span class="ruby-keyword kw">def</span> <span class="ruby-constant">XmlSimple</span>.<span class="ruby-identifier">xml_in</span>(<span class="ruby-identifier">string</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">options</span> = <span class="ruby-keyword kw">nil</span>)
202:     <span class="ruby-identifier">xml_simple</span> = <span class="ruby-constant">XmlSimple</span>.<span class="ruby-identifier">new</span>
203:     <span class="ruby-identifier">xml_simple</span>.<span class="ruby-identifier">xml_in</span>(<span class="ruby-identifier">string</span>, <span class="ruby-identifier">options</span>)
204:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000009" class="method-detail">
        <a name="M000009"></a>

        <div class="method-heading">
          <a href="#M000009" class="method-signature">
          <span class="method-name">xml_in_string</span><span class="method-args">(string, options = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000009-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/hash/conversions.rb, line 22</span>
22:   <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">xml_in_string</span>(<span class="ruby-identifier">string</span>, <span class="ruby-identifier">options</span> = <span class="ruby-keyword kw">nil</span>)
23:     <span class="ruby-identifier">new</span>.<span class="ruby-identifier">xml_in_string</span>(<span class="ruby-identifier">string</span>, <span class="ruby-identifier">options</span>)
24:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000014" class="method-detail">
        <a name="M000014"></a>

        <div class="method-heading">
          <a href="#M000014" class="method-signature">
          <span class="method-name">xml_out</span><span class="method-args">(hash, options = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
This is the functional version of the instance method <a
href="XmlSimple.html#M000013">xml_out</a>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000014-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000014-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb, line 257</span>
257:   <span class="ruby-keyword kw">def</span> <span class="ruby-constant">XmlSimple</span>.<span class="ruby-identifier">xml_out</span>(<span class="ruby-identifier">hash</span>, <span class="ruby-identifier">options</span> = <span class="ruby-keyword kw">nil</span>)
258:     <span class="ruby-identifier">xml_simple</span> = <span class="ruby-constant">XmlSimple</span>.<span class="ruby-identifier">new</span>
259:     <span class="ruby-identifier">xml_simple</span>.<span class="ruby-identifier">xml_out</span>(<span class="ruby-identifier">hash</span>, <span class="ruby-identifier">options</span>)
260:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000011" class="method-detail">
        <a name="M000011"></a>

        <div class="method-heading">
          <a href="#M000011" class="method-signature">
          <span class="method-name">xml_in</span><span class="method-args">(string = nil, options = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Converts an XML document in the same way as the Perl module XML::Simple.
</p>
<table>
<tr><td valign="top">string:</td><td>XML source. Could be one of the following:

<ul>
<li>nil: Tries to load and parse &#8217;&lt;scriptname&gt;.xml&#8217;.

</li>
<li>filename: Tries to load and parse filename.

</li>
<li>IO object: Reads from object until EOF is detected and parses result.

</li>
<li>XML string: Parses string.

</li>
</ul>
</td></tr>
<tr><td valign="top">options:</td><td>Options to be used.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000011-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb, line 149</span>
149:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">xml_in</span>(<span class="ruby-identifier">string</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">options</span> = <span class="ruby-keyword kw">nil</span>)
150:     <span class="ruby-identifier">handle_options</span>(<span class="ruby-value str">'in'</span>, <span class="ruby-identifier">options</span>)
151: 
152:     <span class="ruby-comment cmt"># If no XML string or filename was supplied look for scriptname.xml.</span>
153:     <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">string</span>.<span class="ruby-identifier">nil?</span>
154:       <span class="ruby-identifier">string</span> = <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-identifier">basename</span>(<span class="ruby-identifier">$0</span>)
155:       <span class="ruby-identifier">string</span>.<span class="ruby-identifier">sub!</span>(<span class="ruby-regexp re">/\.[^.]+$/</span>, <span class="ruby-value str">''</span>)
156:       <span class="ruby-identifier">string</span> <span class="ruby-operator">+=</span> <span class="ruby-value str">'.xml'</span>
157: 
158:       <span class="ruby-identifier">directory</span> = <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-identifier">dirname</span>(<span class="ruby-identifier">$0</span>)
159:       <span class="ruby-ivar">@options</span>[<span class="ruby-value str">'searchpath'</span>].<span class="ruby-identifier">unshift</span>(<span class="ruby-identifier">directory</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">directory</span>.<span class="ruby-identifier">nil?</span>
160:     <span class="ruby-keyword kw">end</span>
161: 
162:     <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">string</span>.<span class="ruby-identifier">instance_of?</span>(<span class="ruby-constant">String</span>)
163:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">string</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/&lt;.*?&gt;/</span><span class="ruby-identifier">m</span>
164:         <span class="ruby-ivar">@doc</span> = <span class="ruby-identifier">parse</span>(<span class="ruby-identifier">string</span>)
165:       <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">string</span> <span class="ruby-operator">==</span> <span class="ruby-value str">'-'</span>
166:         <span class="ruby-ivar">@doc</span> = <span class="ruby-identifier">parse</span>(<span class="ruby-identifier">$stdin</span>.<span class="ruby-identifier">readlines</span>.<span class="ruby-identifier">to_s</span>)
167:       <span class="ruby-keyword kw">else</span>
168:         <span class="ruby-identifier">filename</span> = <span class="ruby-identifier">find_xml_file</span>(<span class="ruby-identifier">string</span>, <span class="ruby-ivar">@options</span>[<span class="ruby-value str">'searchpath'</span>])
169: 
170:         <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-value str">'cache'</span>)
171:           <span class="ruby-ivar">@options</span>[<span class="ruby-value str">'cache'</span>].<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">scheme</span><span class="ruby-operator">|</span>
172:             <span class="ruby-keyword kw">case</span>(<span class="ruby-identifier">scheme</span>)
173:             <span class="ruby-keyword kw">when</span> <span class="ruby-value str">'storable'</span>
174:               <span class="ruby-identifier">content</span> = <span class="ruby-ivar">@@cache</span>.<span class="ruby-identifier">restore_storable</span>(<span class="ruby-identifier">filename</span>)
175:             <span class="ruby-keyword kw">when</span> <span class="ruby-value str">'mem_share'</span>
176:               <span class="ruby-identifier">content</span> = <span class="ruby-ivar">@@cache</span>.<span class="ruby-identifier">restore_mem_share</span>(<span class="ruby-identifier">filename</span>)
177:             <span class="ruby-keyword kw">when</span> <span class="ruby-value str">'mem_copy'</span>
178:               <span class="ruby-identifier">content</span> = <span class="ruby-ivar">@@cache</span>.<span class="ruby-identifier">restore_mem_copy</span>(<span class="ruby-identifier">filename</span>)
179:             <span class="ruby-keyword kw">else</span>
180:               <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;Unsupported caching scheme: &lt;#{scheme}&gt;.&quot;</span>
181:             <span class="ruby-keyword kw">end</span>
182:             <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">content</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">content</span>
183:           }
184:         <span class="ruby-keyword kw">end</span>
185:         
186:         <span class="ruby-ivar">@doc</span> = <span class="ruby-identifier">load_xml_file</span>(<span class="ruby-identifier">filename</span>)
187:       <span class="ruby-keyword kw">end</span>
188:     <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">string</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">IO</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">string</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">StringIO</span>)
189:       <span class="ruby-ivar">@doc</span> = <span class="ruby-identifier">parse</span>(<span class="ruby-identifier">string</span>.<span class="ruby-identifier">readlines</span>.<span class="ruby-identifier">to_s</span>)
190:     <span class="ruby-keyword kw">else</span>
191:       <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;Could not parse object of type: &lt;#{string.type}&gt;.&quot;</span>
192:     <span class="ruby-keyword kw">end</span>
193: 
194:     <span class="ruby-identifier">result</span> = <span class="ruby-identifier">collapse</span>(<span class="ruby-ivar">@doc</span>.<span class="ruby-identifier">root</span>)
195:     <span class="ruby-identifier">result</span> = <span class="ruby-ivar">@options</span>[<span class="ruby-value str">'keeproot'</span>] <span class="ruby-operator">?</span> <span class="ruby-identifier">merge</span>({}, <span class="ruby-ivar">@doc</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">name</span>, <span class="ruby-identifier">result</span>) <span class="ruby-operator">:</span> <span class="ruby-identifier">result</span>
196:     <span class="ruby-identifier">put_into_cache</span>(<span class="ruby-identifier">result</span>, <span class="ruby-identifier">filename</span>)
197:     <span class="ruby-identifier">result</span>
198:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000008" class="method-detail">
        <a name="M000008"></a>

        <div class="method-heading">
          <a href="#M000008" class="method-signature">
          <span class="method-name">xml_in_string</span><span class="method-args">(string, options = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Same as <a href="XmlSimple.html#M000011">xml_in</a> but doesn&#8216;t try
to smartly shoot itself in the foot.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000008-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/core_ext/hash/conversions.rb, line 9</span>
 9:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">xml_in_string</span>(<span class="ruby-identifier">string</span>, <span class="ruby-identifier">options</span> = <span class="ruby-keyword kw">nil</span>)
10:     <span class="ruby-identifier">handle_options</span>(<span class="ruby-value str">'in'</span>, <span class="ruby-identifier">options</span>)
11: 
12:     <span class="ruby-ivar">@doc</span> = <span class="ruby-identifier">parse</span>(<span class="ruby-identifier">string</span>)
13:     <span class="ruby-identifier">result</span> = <span class="ruby-identifier">collapse</span>(<span class="ruby-ivar">@doc</span>.<span class="ruby-identifier">root</span>)
14: 
15:     <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@options</span>[<span class="ruby-value str">'keeproot'</span>]
16:       <span class="ruby-identifier">merge</span>({}, <span class="ruby-ivar">@doc</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">name</span>, <span class="ruby-identifier">result</span>)
17:     <span class="ruby-keyword kw">else</span>
18:       <span class="ruby-identifier">result</span>
19:     <span class="ruby-keyword kw">end</span>
20:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000013" class="method-detail">
        <a name="M000013"></a>

        <div class="method-heading">
          <a href="#M000013" class="method-signature">
          <span class="method-name">xml_out</span><span class="method-args">(ref, options = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Converts a data structure into an XML document.
</p>
<table>
<tr><td valign="top">ref:</td><td>Reference to data structure to be converted into XML.

</td></tr>
<tr><td valign="top">options:</td><td>Options to be used.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000013-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000013-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb, line 212</span>
212:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">xml_out</span>(<span class="ruby-identifier">ref</span>, <span class="ruby-identifier">options</span> = <span class="ruby-keyword kw">nil</span>)
213:     <span class="ruby-identifier">handle_options</span>(<span class="ruby-value str">'out'</span>, <span class="ruby-identifier">options</span>)
214:     <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">ref</span>.<span class="ruby-identifier">instance_of?</span>(<span class="ruby-constant">Array</span>)
215:       <span class="ruby-identifier">ref</span> = { <span class="ruby-ivar">@options</span>[<span class="ruby-value str">'anonymoustag'</span>] =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">ref</span> }
216:     <span class="ruby-keyword kw">end</span>
217: 
218:     <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@options</span>[<span class="ruby-value str">'keeproot'</span>]
219:       <span class="ruby-identifier">keys</span> = <span class="ruby-identifier">ref</span>.<span class="ruby-identifier">keys</span>
220:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">keys</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
221:         <span class="ruby-identifier">ref</span> = <span class="ruby-identifier">ref</span>[<span class="ruby-identifier">keys</span>[<span class="ruby-value">0</span>]]
222:         <span class="ruby-ivar">@options</span>[<span class="ruby-value str">'rootname'</span>] = <span class="ruby-identifier">keys</span>[<span class="ruby-value">0</span>]
223:       <span class="ruby-keyword kw">end</span>
224:     <span class="ruby-keyword kw">elsif</span> <span class="ruby-ivar">@options</span>[<span class="ruby-value str">'rootname'</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">''</span>
225:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">ref</span>.<span class="ruby-identifier">instance_of?</span>(<span class="ruby-constant">Hash</span>)
226:         <span class="ruby-identifier">refsave</span> = <span class="ruby-identifier">ref</span>
227:         <span class="ruby-identifier">ref</span> = {}
228:         <span class="ruby-identifier">refsave</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
229:           <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">scalar</span>(<span class="ruby-identifier">value</span>)
230:             <span class="ruby-identifier">ref</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">value</span>
231:           <span class="ruby-keyword kw">else</span>
232:             <span class="ruby-identifier">ref</span>[<span class="ruby-identifier">key</span>] = [ <span class="ruby-identifier">value</span>.<span class="ruby-identifier">to_s</span> ]
233:           <span class="ruby-keyword kw">end</span>
234:         }
235:       <span class="ruby-keyword kw">end</span>
236:     <span class="ruby-keyword kw">end</span>
237: 
238:     <span class="ruby-ivar">@ancestors</span> = []
239:     <span class="ruby-identifier">xml</span> = <span class="ruby-identifier">value_to_xml</span>(<span class="ruby-identifier">ref</span>, <span class="ruby-ivar">@options</span>[<span class="ruby-value str">'rootname'</span>], <span class="ruby-value str">''</span>)
240:     <span class="ruby-ivar">@ancestors</span> = <span class="ruby-keyword kw">nil</span>
241: 
242:     <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@options</span>[<span class="ruby-value str">'xmldeclaration'</span>]
243:       <span class="ruby-identifier">xml</span> = <span class="ruby-ivar">@options</span>[<span class="ruby-value str">'xmldeclaration'</span>] <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;\n&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">xml</span>
244:     <span class="ruby-keyword kw">end</span>
245: 
246:     <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-value str">'outputfile'</span>)
247:       <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@options</span>[<span class="ruby-value str">'outputfile'</span>].<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">IO</span>)
248:         <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@options</span>[<span class="ruby-value str">'outputfile'</span>].<span class="ruby-identifier">write</span>(<span class="ruby-identifier">xml</span>)
249:       <span class="ruby-keyword kw">else</span>
250:         <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-ivar">@options</span>[<span class="ruby-value str">'outputfile'</span>], <span class="ruby-value str">&quot;w&quot;</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">file</span><span class="ruby-operator">|</span> <span class="ruby-identifier">file</span>.<span class="ruby-identifier">write</span>(<span class="ruby-identifier">xml</span>) }
251:       <span class="ruby-keyword kw">end</span>
252:     <span class="ruby-keyword kw">end</span>
253:     <span class="ruby-identifier">xml</span>
254:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>